local skel = fk.CreateSkill {
  name = "lb__shefu",
}

Fk:loadTranslationTable {
  ["lb__shefu"] = "摄服",
  --[":lb__shefu"] = "你于回合内使用首张牌指定唯一目标后，若此牌为【杀】，你可以秘密选择两项并于依序执行：<br>"..
  --9.8
  [":lb__shefu"] = "你于回合内使用首张基本牌指定唯一目标后，若此牌为【杀】，你可以秘密选择两项并于依序执行：<br>" ..
      "1.若未被抵消，你视为使用一张【杀】；<br>" ..
      "2.若未被抵消，你摸两张牌；<br>" ..
      "3.若被抵消，你弃置目标一张牌；<br>" ..
      "4.若被抵消，你失去1点体力并执行所有未选择项。",

  ["#lb__shefu-1"] = "若未被抵消，你视为使用一张【杀】",
  ["#lb__shefu-2"] = "若未被抵消，你摸两张牌",
  ["#lb__shefu-3"] = "若被抵消，你弃置目标一张牌",
  ["#lb__shefu-4"] = "若被抵消，你失去1点体力并执行所有未选择项",

  ["#lb__shefu_dis"] = "摄服：弃置 %dest 一张牌",

  ["$lb__shefu1"] = "束手就擒！",
  ["$lb__shefu2"] = "魔阴，不赦。",
}

skel:addEffect(fk.TargetSpecified, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if data:isOnlyTarget(data.to) and player:hasSkill(skel.name) and target == player and
        data.card.trueName == "slash" then
      return (#player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data
        return use.from == player and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) == 1)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local all = { "#lb__shefu-1", "#lb__shefu-2", "#lb__shefu-3", "#lb__shefu-4" } --,"Cancel"
    local choices = player.room:askToChoices(player, {
      choices = all,
      min_num = 2,
      max_num = 2,
      skill_name = "lb__shefu"
    })
    event:setCostData(self, { choices = choices })
    return #choices > 1
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.lb__shefu_list = event:getCostData(self).choices
  end,
})

skel:addEffect(fk.CardEffectCancelledOut, {
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and
        data.extra_data and data.extra_data.lb__shefu_list and
        (table.contains(data.extra_data.lb__shefu_list, "#lb__shefu-3") or
          table.contains(data.extra_data.lb__shefu_list, "#lb__shefu-4"))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local m = data.extra_data.lb__shefu_list
    if table.contains(m, "#lb__shefu-3") and not to:isNude() then
      local cid = room:askToChooseCard(player, {
        target = to,
        flag = "he",
        skill_name = skel.name,
        prompt = "#lb__shefu_dis::" .. to.id,
      })
      room:throwCard(cid, "lb__shefu", to, player)
    end
    if table.contains(m, "#lb__shefu-4") then
      room:loseHp(player, 1, "lb__shefu")
      for _, v in ipairs({ "#lb__shefu-1", "#lb__shefu-2", "#lb__shefu-3" }) do
        if player.dead then break end
        if not table.contains(m, v) then
          if v == "#lb__shefu-1" then
            room:askToUseVirtualCard(player, {
              name = "slash",
              skill_name = skel.name,
              cancelable = false,
            })
          elseif v == "#lb__shefu-2" then
            player:drawCards(2, "lb__shefu")
          elseif v == "#lb__shefu-3" and not to:isNude() and not to.dead then
            local cid = room:askToChooseCard(player, {
              target = to,
              flag = "he",
              skill_name = skel.name,
              prompt = "#lb__shefu_dis::" .. to.id,
            })
            room:throwCard(cid, "lb__shefu", to, player)
          end
        end
      end
    end
  end,
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and
        data.extra_data and data.extra_data.lb__shefu_list
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data.lb__shefu_dixiao = true
  end,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.trueName == "slash"
        and data.extra_data and data.extra_data.lb__shefu_list and not data.extra_data.lb__shefu_dixiao and
        (table.contains(data.extra_data.lb__shefu_list, "#lb__shefu-1") or
          table.contains(data.extra_data.lb__shefu_list, "#lb__shefu-2"))
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local m = data.extra_data.lb__shefu_list
    if table.contains(m, "#lb__shefu-1") then
      room:askToUseVirtualCard(player, {
        name = "slash",
        skill_name = skel.name,
        cancelable = false,
      })
    end
    if table.contains(m, "#lb__shefu-2") then
      player:drawCards(2, "lb__shefu")
    end
  end,
})

return skel
